{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "ff6e6064-3e3f-42c1-835d-4dd64cefe91a",
   "metadata": {
    "tags": []
   },
   "outputs": [],
   "source": [
    "import numpy as np"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "id": "1de1b5a3-438c-4695-a7cc-1e89d20f639e",
   "metadata": {
    "tags": []
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0.23133039183594684"
      ]
     },
     "execution_count": 10,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "np.random.rand()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "da0c06b3-63c4-4883-90a2-80d7aa3e83a5",
   "metadata": {
    "tags": []
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[0.2873872 , 0.5550251 ],\n",
       "       [0.56209849, 0.33232816],\n",
       "       [0.77914013, 0.28389291]])"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "np.random.rand(3,2) #生成一个随机矩阵"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "id": "39f096fb-b018-4980-9dbd-45003ba5b523",
   "metadata": {
    "tags": []
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[4, 0, 4, 6],\n",
       "       [2, 7, 2, 7],\n",
       "       [4, 6, 0, 1],\n",
       "       [8, 7, 0, 4],\n",
       "       [7, 7, 6, 4]])"
      ]
     },
     "execution_count": 15,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "np.random.randint(10, size=(5,4)) #随机整数"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "id": "55f2fa59-02a5-4624-afe0-fc6103e4034f",
   "metadata": {
    "tags": []
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0.4681733030136255"
      ]
     },
     "execution_count": 11,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "np.random.random_sample()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "id": "55adb84d-7486-4eb3-9ff8-5dd498517527",
   "metadata": {
    "tags": []
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([8, 9, 9])"
      ]
     },
     "execution_count": 13,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "np.random.randint(8,10,3)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "id": "5fddc133-869d-4f50-923a-98325573759b",
   "metadata": {
    "tags": []
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([0.14502772, 0.06228194, 0.09444929, 0.14746336])"
      ]
     },
     "execution_count": 18,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "miu, sigma = 0, 0.1\n",
    "np.random.normal(miu, sigma, 4)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "id": "1c39ba77-e428-4b0d-b042-591dad3d527d",
   "metadata": {
    "tags": []
   },
   "outputs": [],
   "source": [
    "np.set_printoptions(precision=3) #修改np输出精度"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "id": "94795a31-6136-449c-a598-de226935d06b",
   "metadata": {
    "tags": []
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([ 0.131, -0.061, -0.006,  0.052])"
      ]
     },
     "execution_count": 23,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "miu, sigma = 0, 0.1\n",
    "np.random.normal(miu, sigma, 4)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "ddb3b438-5b3a-4dae-83f5-58f0e7c365b4",
   "metadata": {},
   "source": [
    "___洗牌___"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "id": "f11db0ca-7c94-4195-8bbb-8fd9e222667e",
   "metadata": {
    "tags": []
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([0, 1, 2, 3, 4, 5, 6, 7, 8, 9])"
      ]
     },
     "execution_count": 24,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "fang_array = np.arange(10)\n",
    "fang_array"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 49,
   "id": "2c1fa0db-1ee8-42fd-a380-44dc7a315ab7",
   "metadata": {
    "tags": []
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([0, 2, 1, 8, 9, 7, 6, 3, 4, 5])"
      ]
     },
     "execution_count": 49,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "np.random.shuffle(fang_array) #打乱顺序\n",
    "fang_array"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "1f29a5da-d0d0-4a3a-a673-38f6b4e0aafa",
   "metadata": {
    "tags": []
   },
   "source": [
    "___随机种子___"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 52,
   "id": "f6927dc5-42ea-4835-953e-b1d5294997ca",
   "metadata": {
    "tags": []
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([-0.02 ,  0.048, -0.052, -0.056,  0.197,  0.139,  0.009,  0.028,\n",
       "        0.077,  0.125])"
      ]
     },
     "execution_count": 52,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "np.random.seed(12345) #用种子生成随机值，随机值固定\n",
    "(miu, sigma) = (0, 0.1)\n",
    "np.random.normal(miu, sigma, 10)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "c23f7f4d-6c41-4316-8307-11b7465d05a1",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.10.10"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
